package codetop.dp;

public class Code213 {
    public int rob(int[] nums) {
        if (nums.length==0)return 0;
        if (nums.length==1)return nums[0];
        return Math.max(sup(nums,0,nums.length-2),sup(nums,1,nums.length-1));
    }
    public int sup(int []nums,int start,int end){
        int dp[]=new int[end-start+2];
        dp[1]=nums[start];
        int max=dp[1];
        for (int i = start+1; i <=end ; i++) {
            dp[i-start+1]=Math.max(dp[i-start],dp[i-start-1]+nums[i]);
            max=Math.max(max,dp[i-start+1]);

        }
        return max;
    }

}
